/* Copyright (c) 2006 celumsolutions. All Rights Reserved. */
package com.swingolf.service;

import com.swingolf.dao.PlayerDAO;
import com.swingolf.model.Player;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * @author rtm
 * @since 14.09.11
 */
@Repository
public class PlayerService {

  @Autowired PlayerDAO playerDAO;

  public List<Player> findPlayers() {
    return playerDAO.findAll();
  }

  public void updatePlayer(Player player) {
    playerDAO.update(player);
  }

  public void savePlayer(Player player) {
    playerDAO.save(player);
  }

  public void deletePlayer(Player player) {
    playerDAO.delete(player);
  }

  public Player findPlayer(Long id) {
    List<Player> players = playerDAO.findAll();
    for (Player player : players) {
      if (player.getId().equals(id)) {
        return player;
      }

    }
    return null;
  }
}
